package com.ruoyi.system.controller;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.dto.InvoiceCustomerDto;
import com.ruoyi.system.domain.dto.InvoiceMessageDto;
import com.ruoyi.system.domain.dto.RoomDto;
import com.ruoyi.system.service.IInvoiceMessageService;
import com.ruoyi.system.service.IInvoiceSumService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InvoiceCustomer;
import com.ruoyi.system.service.IInvoiceCustomerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2021-09-02
 */
@RestController
@RequestMapping("/system/customer")
public class InvoiceController extends BaseController
{
    @Autowired
    private IInvoiceCustomerService invoiceCustomerService;
    @Autowired
    private IInvoiceMessageService invoiceMessageService;
    @Autowired
    private IInvoiceSumService invoiceSumService;
    
    /**
     * 导入客户表
     */
    @GetMapping("/importCustomerAndMessage")
    public AjaxResult importCustomerAndMessage(MultipartFile file1, MultipartFile file2) throws Exception{
        //客户明细
        ExcelUtil<InvoiceCustomerDto> util1 = new ExcelUtil<InvoiceCustomerDto>(InvoiceCustomerDto.class);
        List<InvoiceCustomerDto> invoiceCustomerDtoList = util1.importExcel(file1.getInputStream());
        //发票
        ExcelUtil<InvoiceMessageDto> util2 = new ExcelUtil<InvoiceMessageDto>(InvoiceMessageDto.class);
        List<InvoiceMessageDto> invoiceMessageDtoList = util2.importExcel(file2.getInputStream());
    
        List<RoomDto> roomDtoList = new ArrayList<>();
        for(InvoiceMessageDto invoiceMessageDto : invoiceMessageDtoList){
            String title = invoiceMessageDto.getTitle();
            if(StringUtils.isNotBlank(title)){
                for(InvoiceCustomerDto invoiceCustomerDto : invoiceCustomerDtoList){
                
                }
            }
        }
        
        //导出
        ExcelUtil<RoomDto> util3 = new ExcelUtil<RoomDto>(RoomDto.class);
        return util3.exportExcel(roomDtoList, "房间合计");
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('system:customer:export')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(InvoiceCustomer invoiceCustomer)
    {
        List<InvoiceCustomer> list = invoiceCustomerService.selectInvoiceCustomerList(invoiceCustomer);
        ExcelUtil<InvoiceCustomer> util = new ExcelUtil<InvoiceCustomer>(InvoiceCustomer.class);
        return util.exportExcel(list, "【请填写功能名称】数据");
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('system:customer:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(invoiceCustomerService.deleteInvoiceCustomerByIds(ids));
    }
}
